var settings = require('../settings')

/*
  mongoose.js ：建立数据库连接
*/
var mongoose = require('mongoose') // 引入 mongoose
mongoose.Promise = global.Promise;
mongoose.set('useFindAndModify', false);
mongoose.connect(settings.MONGO_URL, {
  useNewUrlParser: true,
  poolSize: 50
})

// connect() 返回一个状态待定（pending）的连接，可以用来判断连接成功或失败
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
  console.log("Successful connection to " + settings.MONGO_URL)
});
